﻿using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1.Templates
{
    public class DapperIBLLTemplate : TemplatesBase
    {
        public DapperIBLLTemplate() : base("IBll")
        {
        }

        /// <summary>
        /// 命名空间
        /// </summary>
        public override string namespacestr
        {
            get
            {
                return Entrance.attrnamespacestr + ".BLL";
            }
        }

        public override void SaveFile(List<EntityAttrList> list)
        {
            if (list != null && list.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                //表描述
                string txtTableDesc = list.FirstOrDefault().TableDescription;
                string txtTableName = list.FirstOrDefault().TableName;
                stringBuilder.AppendLine("using DapperDal.DapperBase;");
                stringBuilder.AppendLine("using " + Entrance.attrnamespacestr + ".Entity; ");
                stringBuilder.AppendLine("");
                stringBuilder.AppendLine("namespace " + namespacestr);
                stringBuilder.AppendLine("{");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("/// <summary>");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("/// " + txtTableDesc + "业务接口层");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("/// <summary>");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("public interface I" + txtTableName + "Bll" + " : IBaseBll<" + GetPrimaryKey(list) + "," + txtTableName + "Entity>");
                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("{");



                stringBuilder.AppendLine("");



                stringBuilder.Append(new string(' ', 4));
                stringBuilder.AppendLine("}");
                stringBuilder.AppendLine("}");
                CreateFile("I" + txtTableName, stringBuilder.ToString(), "Bll");
            }
        }
    }
}
